/**
 * @Author：ming
 * @Date：2023/9/26 4:45 PM
 * @Filename：Lc98
 */

import java.util.ArrayList;
import java.util.List;

/**
 * @author ming
 */
public class Lc98 {
    public boolean isValidBST(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        look(root,list);
        int[] a = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            a[i]=list.get(i);
        }

        for (int i = 0; i < a.length; i++) {
            if(a[i]<a[i+1]){
                continue;
            }else {
                return false;
            }
        }

        return true;
    }

    public static void look(TreeNode root, List l){
        if(root.left!=null){
            look(root.left,l);
        }
        l.add(root.val);

        if(root.right!=null){
            look(root.right,l);
        }
    }
}
